﻿using System;
using System.Web.Security;
using System.Web.UI.WebControls;
using Model;
using Model.Entities;
using MusicSite.ViewClasses;

namespace MusicSite.Views.Content.User
{
    public partial class Login : BasePage
    {
        private UserProvider userProv = new UserProvider();
        protected void LoginActionClick(object sender, EventArgs e)
        {
            if (IsValid)
            {
                bool curUser = userProv.GetUser(login.Text, password.Text);
                if (curUser)
                {
                    Session["UserRole"] = userProv.GetUserRole(login.Text);
                    FormsAuthentication.RedirectFromLoginPage(login.Text, false);
                }
                else
                    invalidLogin.Text = "***Invalid user name or password!";
            }
        }

        protected void ValidateLength(object sender, ServerValidateEventArgs args)
        {
            string str = args.Value;
            if (str.Length > 30)
                args.IsValid = false;
            else
                args.IsValid = true;
        }
    }
}
